
public class ArrayCopyTest {
	
	private static final int MAX_SIZE = 10_000_000;
	private static final int NEXPERIMENTS = 1000;
	int [] array; 
	int [] arrayCopy;
	
	public ArrayCopyTest() {
		array = new int [MAX_SIZE];
		arrayCopy = new int [MAX_SIZE];
		initializeArray();
	}
	
	private void initializeArray() {
		for (int i = 0; i < MAX_SIZE; i++) {
			array[i] = i;
		}
	}

	
	public static void main(String[] args) {

		ArrayCopyTest test = new ArrayCopyTest();
		
		for (int i = 0; i < NEXPERIMENTS; i++) {
			System.out.println("-----------------------");
			System.out.println(" ArraySize| ratio");
			for (int copySize = 1000; copySize <= MAX_SIZE; copySize*=10) {
				System.out.printf("%10d: %.5f%n", copySize, test.calcRatio(copySize) );
			}
		}

	}

	private double calcRatio(int size) {
		return (double)getTimeOfManualArrayCopy(size) / getTimeOfSystemArrayCopy(size);
	}

	private long getTimeOfSystemArrayCopy(int copySize) {
		long startTime = System.nanoTime();
		System.arraycopy(array, 0, arrayCopy, 0, copySize);
		return System.nanoTime() - startTime;
	}

	private long getTimeOfManualArrayCopy(int copySize) {
		long startTime = System.nanoTime();
		for (int i = 0; i < copySize; i++) {
			array[i] = arrayCopy[i];
		}
		return System.nanoTime() - startTime;
	}

}
